using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class Level06Manager : MonoBehaviour
{
    [Header("天数文字引用")] [SerializeField] private TMP_Text _dayText;
    [Header("滑动条引用")] [SerializeField] private Slider _slider;

    private float _unit = 2;
    private float _curTime = 12;
    private float _maxTime = 36;
    private int _dayCount = 0;
    private int _dayCountMax = 120;
    
    private void Start()
    {
        PlayerController.Instance.HidePlayer();
        _curTime *= _unit;
        _maxTime *= _unit;
    }

    private void Update()
    {
        if (_curTime < _maxTime)
        {
            _slider.value = Mathf.Lerp(_slider.minValue, _slider.maxValue, _curTime / _maxTime);
            _dayCount = (int)Mathf.Lerp(0, _dayCountMax, (_curTime - 12 * _unit) / _maxTime) + 1;
            _curTime += Time.deltaTime;
            _dayText.text = _dayCount + " 天";
        }
    }

    public void OnLevel06BtnPressed()
    {
        if (_slider.value >= 50 && _slider.value <= 70)
        {
            GameManager.Instance.Clearance(6);
            MapManager.Instance.SetLastSceneIndex(6);
        }
        else
        {
            UIManager.Instance.ShowFailPanel();
        }

        enabled = false;
    }
}
